home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / mike40c.arc / INSTR.C < prev    next >
Text File  |  1986-10-24  |  1KB  |  43 lines

  1. /************************************************************************
  2.       instr(pos, string, target)                                        
  3.             Beginning at offset pos, in string, find target.          
  4.             returns starting position in string of target if found,  
  5.             returns (-1) if not found                                 
  6.             <?> can be used as wild card in target
  7.             This routine is not case sensitive.
  8. ************************************************************************/
  9. instr(p, s, t)
  10. char *s, *t;
  11. int p;
  12. {
  13.     int i, j, k, l;
  14.     char up[80];
  15.     register char *a, *b;
  16.  
  17.     l = strlen(s + p) + p;     /* So we don't wild card beyond EOS */
  18.     strcpy(up, s);
  19.     strupr(up);   /* convert both to upper case for compare */
  20.     strupr(t);
  21.  
  22.     for (i = p; up[i]; i++) {  /* Loop thru string.  */
  23.         a = &up[i];
  24.         k = 0;  /* Reset target to beginning.  */
  25.         for (j = i, b = &t[k]; *b; a++, b++, j++) {  /* Loop thru target. */
  26.             while ( *b == '?' && j <= l)
  27.                 a++, b++;      /* Skip if ? in target. */
  28.  
  29.             if (*a != *b)      /* Check for char match.  */
  30.                 break;         /* Incr thru string if not. */
  31.  
  32.         }
  33.  
  34.         if (*b == '\0') /* Reached end of target without a mismatch.*/
  35.             return(i); /* Return offset where match started.  */
  36.  
  37.     }
  38.     return(-1); /* Reached end of string without a match.  */
  39.  
  40. }
  41.  
  42.  
  43.